#!/bin/bash

start(){
	pid=`ps aux | grep -v grep | grep "/usr/bin/python3 manage.py runserver" | awk '{print $2}'`
	if [ ! -n "$pid" ];
	then
		nohup ./OpStart.sh >logs/OpManager.log 2>&1 &
	else
		stop
		nohup ./OpStart.sh >logs/OpManager.log 2>&1 &
	fi

	if [ $? -eq 0 ];
	then
        echo 启动成功，开始查看日志
        tail -f logs/OpManager.log
	else
		echo 启动失败
		echo /dev/null > logs/OpManger.pid
	fi
}

stop(){
	ps aux | grep -v grep | grep "/usr/bin/python3 manage.py runserver"| awk '{print $2}' | xargs kill  && echo 关闭OP || echo 关闭失败
}

$1
